package xyz.hubery.controller;

import com.lmax.disruptor.EventHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import xyz.hubery.disruptor.OrderEvent;
import xyz.hubery.disruptor.OrderEventHandler;
import xyz.hubery.domain.DepthItemVo;
import xyz.hubery.feign.MatchServiceFeign;
import xyz.hubery.util.DepthCacheManager;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/match")
public class MatchController implements MatchServiceFeign {

    @Autowired
    private DepthCacheManager depthCacheManager;

    @Autowired
    private EventHandler<OrderEvent>[] eventHandlers;

    @GetMapping("/plates")
    @Override
    public Map<String, List<DepthItemVo>> querySymbolDepth(@RequestParam String symbol) {
        return depthCacheManager.getSymbolDepth(symbol); // 直接从缓存中获取

//        for (EventHandler<OrderEvent> eventHandler : eventHandlers) {
//            OrderEventHandler orderEventHandler = (OrderEventHandler) eventHandler;
//            if(orderEventHandler.getSymbol().equals(symbol)) {
//                HashMap<String, List<DepthItemVo>> symbolDepthMap = new HashMap<>();
//                symbolDepthMap.put("bids",orderEventHandler.getOrderBooks().getBuyTradePlate().getItems());
//                symbolDepthMap.put("asks",orderEventHandler.getOrderBooks().getSellTradePlate().getItems());
//                return symbolDepthMap;
//            }
//        }
//        return Collections.emptyMap();
    }
}
